#ifndef __PORT_H
#define __PORT_H

#include "hash.h"

class Port
{
  // Data
  int port;
  double starttime;
  int waitfor;

 public:
  // Constructors
  Port();
  Port(int, double);
  Port(const Port&);

  // Functions
  void Init(int, double);
  void UpdateStarttime(double);
  int AddConnection();
  int RemoveConnection();
  int GetPort();
  double GetTime();
  int GetConnectionCount();

  // Operators
  int operator>(const Port&);
  int operator<(const Port&);
  friend ostream& operator<<(ostream&, const Port&);
};

Port::Port()
{
  Init(0,MAXT);
}

Port::Port(int p, double t)
{
  Init(p, t);
}

Port::Port(const Port& p)
{
  port = p.port;
  starttime = p.starttime;
  waitfor = p.waitfor;
}

void Port::Init(int p, double t)
{
  port = p;
  starttime = t;
  waitfor = 0;
}

void Port::UpdateStarttime(double t)
{
  if (t < starttime)
    starttime = t;
}

int Port::AddConnection()
{
  return ++waitfor;
}

int Port::RemoveConnection()
{
  return --waitfor;
}

int Port::GetPort()
{
  return port;
}

double Port::GetTime()
{
  return starttime;
}


int Port::GetConnectionCount()
{
  return waitfor;
}

int Port::operator>(const Port& p)
{
  return starttime > p.starttime;
}

int Port::operator<(const Port& p)
{
  return starttime < p.starttime;
}

ostream& operator<<(ostream& out, const Port& p)
{
  out<<"Port number " << p.port << " start time " << p.starttime
     << " connections " << p.waitfor;
}

#endif
